package net.schastny.contactmanager.dao;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import net.schastny.contactmanager.domain.Shake;

@Repository
public class ShakeDAOImpl implements ShakeDAO {

	@Autowired
	private SessionFactory sessionFactory;

	public void addShake(Shake shake) {
		sessionFactory.getCurrentSession().save(shake);

	}

	@SuppressWarnings("unchecked")
	public List<Shake> listShake() {
		return sessionFactory.getCurrentSession().createQuery("from Shake")
				.list();

	}

	public void removeShake(Integer id) {
		Shake shake = (Shake) sessionFactory.getCurrentSession().load(
				Shake.class, id);
		if (null != shake) {
			sessionFactory.getCurrentSession().delete(shake);
		}

	}

}
